package com.ymatou.iapi.withdraw.testcase;

import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.withdraw.parameter.PassApprovalBean;
import com.ymatou.iapi.withdraw.parameter.RejectApprovalBean;
import com.ymatou.iapi.withdraw.parameter.applyAlipayWithDrawForBuyerBean;
import com.ymatou.iapi.withdraw.parameter.applyAlipayWithDrawForSellerBean;
import com.ymatou.iapi.withdraw.parameter.applyBankWithDrawForBuyerBean;
import com.ymatou.iapi.withdraw.parameter.applyBankWithDrawForSellerBean;
import com.ymatou.iapi.withdraw.parameter.applyXloboWithDrawForSellerBean;
import com.ymatou.iapi.withdraw.service.PassApprovalCall;
import com.ymatou.iapi.withdraw.service.RejectApprovalCall;
import com.ymatou.iapi.withdraw.service.applyAlipayWithDrawForBuyerCall;
import com.ymatou.iapi.withdraw.service.applyAlipayWithDrawForSellerCall;
import com.ymatou.iapi.withdraw.service.applyBankWithDrawForBuyerCall;
import com.ymatou.iapi.withdraw.service.applyBankWithDrawForSellerCall;
import com.ymatou.iapi.withdraw.service.applyXloboWithDrawForSellerCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.AccountCallServiceV2;
import com.ymttest.database.model.withdraw.Ymt_InvoiceOperationLog;
import com.ymttest.database.model.withdraw.Ymt_InvoiceOperationLogExample;
import com.ymttest.database.model.withdraw.Ymt_WithDrawCounter;
import com.ymttest.database.model.withdraw.Ymt_WithDrawCounterExample;
import com.ymttest.database.model.withdraw.Ymt_WithDrawInvoice;
import com.ymttest.database.model.withdraw.Ymt_WithDrawInvoiceExample;
import com.ymttest.database.sqlwapper.WithdrawWapper;
import com.ymttest.utils.TestDataManager;
/**
*审核拒绝--买家/买手提现单运营审核
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_RejectApproval{
	private static RejectApprovalBean bean;
	private static RejectApprovalCall call;
	Ymt_WithDrawInvoiceExample ymtinvoive=new Ymt_WithDrawInvoiceExample();//提现申请信息主表
	WithdrawWapper WithdrawWapper=new WithdrawWapper();
	Ymt_InvoiceOperationLogExample ymtoperationlog=new Ymt_InvoiceOperationLogExample();//单据操作日志表
	Ymt_WithDrawCounterExample ymtcounter=new Ymt_WithDrawCounterExample();//安利会提现计数
	
	private final int sellerid=3383;
	private final String sellerName="wesper";
	
	private final int userId=4085;
	private final String userName="lunchzhao";

	private final String alipayAccountNo_user="18621614677";
	private final String alipayAccountName_user="wuwen";
	private final String alipayAccountName_Id_user="9d53eb3a-5867-4334-9735-269156eb7a16";
	
	private final String fundAccountId_sellerId="925CF663-FCBA-4380-846B-32162E58C345";
	private final String fundAccountName_sellerId="吴文";
	private final String fundAccountNo_sellerId="123456789123";
	
	private final String fundAccountId_buer="925CF663-FCBA-4380-846B-32162E58C317";
	private final String fundAccountName_buer="吴文买家";
	private final String fundAccountNo_buer="987654321789";
	
	private final String abroadFundAccountId="a0d8378e-af28-45bc-b211-5304d4869829";
	private final String abroadFundAccountName="wuwen";
	private final String abroadFundAccountNo="123456789123456";
	
	private final String alipayAccountNo_seller="18621614678";
	private final String alipayAccountName_seller="wuwenseller";
	private final String alipayAccountName_Id_seller="9d53eb3a-5867-4334-9735-269156eb7a26";
	
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("审核拒绝--买家/买手提现单运营审核");
	}

	@Before
	public void caseUp() {
		bean=new RejectApprovalBean();
		call=new RejectApprovalCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(call.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	
	
	/**
	 * 买手申请到银行卡
	 * @param userId 买家/买手
	 * @throws Exception
	 */
	private  String applyBankForseller() throws Exception {
		
		applyBankWithDrawForSellerBean sellerBean=new applyBankWithDrawForSellerBean();
		applyBankWithDrawForSellerCall sellerCall=new applyBankWithDrawForSellerCall();
		WithdrawWapper WithdrawWapper=new WithdrawWapper();
		
		//给帐号充值
		String accountid = AccountCallServiceV2.getAccountId(sellerid, 1);
		AccountCallServiceV2.resetAccount(accountid, new BigDecimal(999999999),
				new BigDecimal(0));
		//冻结资金
		BigDecimal freeze= WithdrawWapper.getSumFreezebyUserId(sellerid);
		Logger.comment("################冻结资金："+freeze);
		//查看账户余额
		BigDecimal balance=AccountCallServiceV2.getAccountBalance(sellerid, 1);
		Logger.comment("################账户余额："+balance);
		
		sellerBean.setUserId(sellerid);
		sellerBean.setWithDrawChannel(1);
		sellerBean.setAccountTypeId(1);//提现帐户类型Id，默认值:1.人民币余额帐户
	    sellerBean.setWithDrawAmount(new BigDecimal(1000));
	    sellerBean.setBusinessNo(new TestDataManager().getRandomNum(8));
        sellerBean.setRemark("测试提现到国际银行卡");
        sellerBean.setApplyUserId(sellerid);
        sellerBean.setApplyLoginId(sellerName);
        
        sellerBean.setBankAccountName(abroadFundAccountName);
        sellerBean.setBankAccountNo(abroadFundAccountNo);
        sellerBean.setFundAccountId(abroadFundAccountId);
	    sellerBean.setCurrencyType(1);//4 美元 	 1 人名币
        sellerBean.setIdempotentNo(new TestDataManager().getRandomNum(8));
        
        sellerCall.setData(sellerBean);
        sellerCall.callService();	
		return sellerCall.getInvoiceId();

	}
	/**
	 * 买家申请到银行卡
	 * @return
	 * @throws Exception
	 */
	private String applyBankForbuyer() throws Exception {
		applyBankWithDrawForBuyerBean bean=new applyBankWithDrawForBuyerBean();
		applyBankWithDrawForBuyerCall call=new applyBankWithDrawForBuyerCall();
		//给帐号充值
		String accountid = AccountCallServiceV2.getAccountId(userId, 1);
		AccountCallServiceV2.resetAccount(accountid, new BigDecimal(999999),
				new BigDecimal(0));
		//冻结资金
		BigDecimal freeze= WithdrawWapper.getSumFreezebyUserId(userId);
		Logger.comment("################冻结资金："+freeze);
		//查看账户余额
		BigDecimal balance=AccountCallServiceV2.getAccountBalance(userId, 1);
		Logger.comment("################账户余额："+balance);
		
		bean.setUserId(userId);
		bean.setWithDrawChannel(1);
		bean.setAccountTypeId(1);//提现帐户类型Id，默认值:1.人民币余额帐户
	    bean.setWithDrawAmount(new BigDecimal(1000));
	    bean.setBusinessNo(new TestDataManager().getRandomNum(8));
        bean.setRemark("测试提现到国际银行卡");
        bean.setApplyUserId(userId);
        bean.setApplyLoginId(userName);
        
        bean.setBankAccountName(fundAccountName_buer);
        bean.setBankAccountNo(fundAccountNo_buer);
        bean.setFundAccountId(fundAccountId_buer);
	    bean.setCurrencyType(1);//1 人名币
        bean.setIdempotentNo(new TestDataManager().getRandomNum(8));
        
		call.setData(bean);
		call.callService();		
		return call.getInvoiceId();
	}
	private String applyAlipayForSeller() throws Exception
	{
		applyAlipayWithDrawForSellerBean bean=new applyAlipayWithDrawForSellerBean();
		applyAlipayWithDrawForSellerCall call=new applyAlipayWithDrawForSellerCall();
		//给帐号充值
		String accountid = AccountCallServiceV2.getAccountId(userId, 1);
		AccountCallServiceV2.resetAccount(accountid, new BigDecimal(999999),
				new BigDecimal(0));
		
        bean.setUserId(sellerid);
        bean.setUserType(1);//用户类型(0买家，１买手）
        bean.setAccountTypeId(1);//买手提现帐户类型:　1普通人民币账户 RmbAccount,15 拼邮溯源专项保证金,16 黑五专项保证金, 17 全球买手专项保证金,18 预售活动保证金,  19 直播保证金, 20 高客单价保证金中间帐户:　21 系统内部人民币账户
        bean.setWithDrawAmount(new BigDecimal(15));
        bean.setBusinessNo(new TestDataManager().getRandomNum(8));
        bean.setRemark("测试提现到支付宝");
        bean.setApplyUserId(sellerid);
        bean.setApplyLoginId(sellerName);
        bean.setAlipayAccountName(alipayAccountName_seller);
        bean.setAlipayAccountNo(alipayAccountNo_seller);
        bean.setFundAccountId(alipayAccountName_Id_seller);
        bean.setIdempotentNo(new TestDataManager().getRandomNum(8));
        bean.setWithDrawChannel(2);//1.买家PC 2.买手PC站 3.运营后台-资金 4.买家App 5.买手App 6.保证金提现 7.码头提现到贝海 8.专项保证金 9.b2b 10.推手APP
        
		call.setData(bean);
		call.callService();	
		return call.getInvoiceId();
	}
	private String applyXloboForSeller() throws Exception {
		
		applyXloboWithDrawForSellerBean bean=new applyXloboWithDrawForSellerBean();
		applyXloboWithDrawForSellerCall call=new applyXloboWithDrawForSellerCall();
		//给帐号充值
		String accountid = AccountCallServiceV2.getAccountId(sellerid, 1);
		AccountCallServiceV2.resetAccount(accountid, new BigDecimal(999999),
				new BigDecimal(0));
		
        bean.setSellerid(sellerid);
        bean.setAccountTypeId(1);//买手提现帐户类型:　1普通人民币账户 RmbAccount,15 拼邮溯源专项保证金,16 黑五专项保证金, 17 全球买手专项保证金,18 预售活动保证金,  19 直播保证金, 20 高客单价保证金中间帐户:　21 系统内部人民币账户
        bean.setWithDrawAmount(new BigDecimal(5));
        bean.setBusinessNo(new TestDataManager().getRandomNum(8));
        bean.setRemark("测试提现到贝海");
        bean.setApplyUserId(3383);
        bean.setApplyLoginId("wesper");
        bean.setXloboAccountNo("testaccount1");
        bean.setIdempotentNo(new TestDataManager().getRandomNum(8));
        
		call.setData(bean);
		call.callService();	
		return call.getInvoiceId();
	}
	/**
	 * 
	 * @param invoiceId 单据号
	 * @param invoiceStatus 单据状态 对应InvoiceStatusEnum枚举(-1.失效，0.待处理，1.处理中，2. 处理失败，3.已完成)
	 * @param approveStatus0.等待客服审批（等待一级审批） 1.客服审批拒绝（一级审批拒绝，单据作废） 2.客服审批通过（一级审核拒绝，等待二级审批）
	 *  3.财务审批拒绝（二级审批拒绝，单据作废） 4.财务审批通过（二级审批通过，等待三级审批） 5.拒绝支付（三级审批拒绝，单据作废） 6.同意支付（三级审批，该单据完成）
	 * @throws InterruptedException
	 */
	private void check(String invoiceId,int invoiceStatus,int approveStatus) throws InterruptedException
	{
		check_WithDrawInvoice(invoiceId,invoiceStatus,approveStatus);
		check_InvoiceOperationLog(invoiceId);
	}
	private void check_WithDrawInvoice(String invoiceId,int invoiceStatus,int approveStatus) throws InterruptedException
	{
		Logger.comment("1:验证数据表 Ymt_WithDrawInvoice 提现申请信息主表");
		Logger.verifyEquals("true", call.getSuccess(), "验证Success");
		Logger.verifyEquals("200", call.getCode(), "验证Code");
		ymtinvoive.createCriteria().andWithDrawInvoiceIdEqualTo(invoiceId);
		List<Ymt_WithDrawInvoice> invoivelist = WithdrawWapper.selectYmtWithDrawInvoice(ymtinvoive);
        if(invoivelist.size()>0)
        {
        	Ymt_WithDrawInvoice invoive=invoivelist.get(0);
        	Logger.verifyEquals(invoiceStatus, invoive.getInvoiceStatus(), "验证Ymt_WithDrawInvoice数据库中 InvoiceStatus字段 是否正确");
        	Logger.verifyEquals(approveStatus, invoive.getApproveStatus(), "验证Ymt_WithDrawInvoice数据库中 ApproveStatus字段 是否正确");
        	Logger.verifyEquals(true, invoive.getApplyTime().toString().length()>0, "验证Ymt_WithDrawInvoice数据库中ApplyTime");
        	Logger.verifyEquals(true, invoive.getUpdateTime().toString().length()>0, "验证Ymt_WithDrawInvoice数据库中UpdateTime");
        }
        else
        {
        	Logger.verifyEquals(false, true, "Ymt_WithDrawInvoice 数据为空，有问题");
        }
	}
	private Ymt_InvoiceOperationLog check_InvoiceOperationLog(String invoiceId) throws InterruptedException
	{
		//2:InvoiceOperationLog 单据操作日志表
		Logger.comment("2:验证数据表 InvoiceOperationLog 单据操作日志表");
		ymtoperationlog.createCriteria().andInvoiceIdEqualTo(invoiceId);
		Ymt_InvoiceOperationLog operationlog=WithdrawWapper.selectYmtInvoiceOperationLog(ymtoperationlog).stream()
				.filter(a->a.getOperatorId().equals(bean.getApprovalUserId())).findFirst().get();
		/**
		 * 1.扣款单 
			2.调解退款单 
			3.充值单 
			4.备用金单 
			5.冻结单 
			6.解冻单 
			7.提现单 
			8.保证金退款单 
			9.自有账户充值单据 
			10.财务调整单据 
			11.商家日账单 
			12.补贴申请单 
			13.财务调整单据 
			14.提现账户 
			15.优惠券回收单据 
			16.发票 
			17.商家月账单 
			18.预充值单
		 */
		Logger.verifyEquals(7, operationlog.getInvoiceType(), "验证数据库Ymt_InvoiceOperationLog 中的字段InvoiceType=7提现单");
		/**
		 *  1.申请 
			2.作废 
			3.审批(客服审批) 
			4.拒绝(客服拒绝) 
			5.财务审批 
			6.财务拒绝 
			7.拒绝支付（三级审批拒绝，单据作废） 
			8.同意支付（三级审批，该单据完成） 
			9.导入成功 
			10.导入失败 
			11.导出成功 
			12.导出失败 
			13.申请解冻 
			14.审批解冻 
			15.拒绝解冻
		 * 
		 */
		Logger.verifyEquals(4, operationlog.getOperationType(), "验证数据库Ymt_InvoiceOperationLog 中的字段OperationType=4拒绝(客服拒绝)");
        return operationlog;
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_RejectApproval_001() {
		Logger.start(true,"正例-审核拒绝--买手提现单运营审核-提现到银行卡-一级审核拒绝");
		try {
			String invoiceId=applyBankForseller();
			bean.setInvoiceId(invoiceId);
			bean.setApprovalLevel(1);
			bean.setApprovalResult("一级审核_"+TestDataManager.random());
			bean.setApprovalUserId(TestDataManager.getRandomIntNum(5));
			bean.setApprovalUserLoginId("LoginId_"+TestDataManager.getRandomIntNum(5));
			call.setData(bean);
			call.callService();	
			
			check( invoiceId,-1,1) ;
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_RejectApproval_001_1() {
		Logger.start(true,"正例-审核拒绝--买家提现单运营审核-提现到银行卡-一级审核拒绝");
		try {
			String invoiceId=applyBankForbuyer();
			bean.setInvoiceId(invoiceId);
			bean.setApprovalLevel(1);
			bean.setApprovalResult("一级审核_"+TestDataManager.random());
			bean.setApprovalUserId(TestDataManager.getRandomIntNum(5));
			bean.setApprovalUserLoginId("LoginId_"+TestDataManager.getRandomIntNum(5));
			call.setData(bean);
			call.callService();		
			
			check( invoiceId,-1,1) ;	
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_RejectApproval_001_2() {
		Logger.start(true,"正例-审核拒绝--买手提现单运营审核-提现到支付宝-一级审核拒绝");
		try {
			String invoiceId=applyAlipayForSeller();
			bean.setInvoiceId(invoiceId);
			bean.setApprovalLevel(1);
			bean.setApprovalResult("一级审核_"+TestDataManager.random());
			bean.setApprovalUserId(TestDataManager.getRandomIntNum(5));
			bean.setApprovalUserLoginId("LoginId_"+TestDataManager.getRandomIntNum(5));
			call.setData(bean);
			call.callService();	
			
			check( invoiceId,-1,1) ;
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	@Ignore
	public void Tc_RejectApproval_001_3() {
		Logger.start(true,"正例-审核拒绝--买手提现单运营审核-提现到贝海-一级审核拒绝(贝海一级审核是自动,提交申请的时候审核)");
		try {
			
			String invoiceId=applyXloboForSeller();
			bean.setInvoiceId(invoiceId);
			bean.setApprovalLevel(1);
			bean.setApprovalResult("一级审核_"+TestDataManager.random());
			bean.setApprovalUserId(TestDataManager.getRandomIntNum(5));
			bean.setApprovalUserLoginId("LoginId_"+TestDataManager.getRandomIntNum(5));
			call.setData(bean);
			call.callService();	
			
			check_WithDrawInvoice(invoiceId,-1,1);
			
			Logger.comment("2:验证数据表 InvoiceOperationLog 单据操作日志表");
			ymtoperationlog.createCriteria().andInvoiceIdEqualTo(invoiceId);
			Optional<Ymt_InvoiceOperationLog>  operationlogList=WithdrawWapper.selectYmtInvoiceOperationLog(ymtoperationlog).stream()
					.filter(a->a.getOperatorId().equals(-1)).findFirst();
			Logger.verifyEquals(7, operationlogList.get().getInvoiceType(), "验证数据库Ymt_InvoiceOperationLog 中的字段InvoiceType=7提现单");
			Logger.verifyEquals(3, operationlogList.get().getOperationType(), "验证数据库Ymt_InvoiceOperationLog 中的字段OperationType");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_RejectApproval_003() {
		Logger.start(true,"正例-审核拒绝--买家/买手提现单运营审核-二级审核拒绝");
		try {
			PassApprovalBean pbean=new  PassApprovalBean();
			PassApprovalCall pcall=new PassApprovalCall();
			String invoiceId=applyBankForseller();
			//一级审核
			pbean.setInvoiceId(invoiceId);
			pbean.setApprovalLevel(1);
			pbean.setApprovalResult("一级审核通过_"+TestDataManager.random());
			pbean.setApprovalUserId(TestDataManager.getRandomIntNum(5));
			pbean.setApprovalUserLoginId("LoginId_"+TestDataManager.getRandomIntNum(5));
			pcall.setData(pbean);
			pcall.callService();	
			//二级审核拒绝
			bean.setInvoiceId(invoiceId);
			bean.setApprovalLevel(2);
			bean.setApprovalResult("二级审核拒绝_"+TestDataManager.random());
			bean.setApprovalUserId(TestDataManager.getRandomIntNum(5));
			bean.setApprovalUserLoginId("LoginId_"+TestDataManager.getRandomIntNum(5));
			call.setData(bean);
			call.callService();	
			
			check_WithDrawInvoice( invoiceId,-1,3) ;	
			
			Logger.comment("2:验证数据表 InvoiceOperationLog 单据操作日志表");
			
			ymtoperationlog.createCriteria().andInvoiceIdEqualTo(invoiceId);
			Optional<Ymt_InvoiceOperationLog>  operationlogList=WithdrawWapper.selectYmtInvoiceOperationLog(ymtoperationlog).stream()
					.filter(a->a.getOperatorId().equals(bean.getApprovalUserId())).findFirst();
			Logger.verifyEquals(7, operationlogList.get().getInvoiceType(), "验证数据库Ymt_InvoiceOperationLog 中的字段InvoiceType=7提现单");
			Logger.verifyEquals(6, operationlogList.get().getOperationType(), "验证数据库Ymt_InvoiceOperationLog 中的字段OperationType=6财务拒绝");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	

	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_RejectApproval_004() {
		Logger.start(true,"正例-审核拒绝--买家/买手提现单运营审核-三级审核拒绝");
		try {
			PassApprovalBean pbean=new  PassApprovalBean();
			PassApprovalCall pcall=new PassApprovalCall();
			String invoiceId=applyBankForseller();
			//一级审核通过
			pbean.setInvoiceId(invoiceId);
			pbean.setApprovalLevel(1);
			pbean.setApprovalResult("一级审核通过_"+TestDataManager.random());
			pbean.setApprovalUserId(TestDataManager.getRandomIntNum(5));
			pbean.setApprovalUserLoginId("LoginId_"+TestDataManager.getRandomIntNum(5));
			pcall.setData(pbean);
			pcall.callService();
			//二级审核通过
			pbean.setApprovalLevel(2);
			pbean.setApprovalResult("二级审核通过_"+TestDataManager.random());
			pbean.setApprovalUserId(TestDataManager.getRandomIntNum(5));
			pbean.setApprovalUserLoginId("LoginId_"+TestDataManager.getRandomIntNum(5));
			pcall.setData(pbean);
			pcall.callService();
			//三级审核拒绝
			bean.setInvoiceId(invoiceId);
			bean.setApprovalLevel(3);
			bean.setApprovalResult("三级审核拒绝_"+TestDataManager.random());
			bean.setApprovalUserId(TestDataManager.getRandomIntNum(5));
			bean.setApprovalUserLoginId("LoginId_"+TestDataManager.getRandomIntNum(5));
			call.setData(bean);
			call.callService();	
			
			check_WithDrawInvoice( invoiceId,-1,5) ;	
			
			Logger.comment("2:验证数据表 InvoiceOperationLog 单据操作日志表");
			
			ymtoperationlog.createCriteria().andInvoiceIdEqualTo(invoiceId);
			Optional<Ymt_InvoiceOperationLog>  operationlogList=WithdrawWapper.selectYmtInvoiceOperationLog(ymtoperationlog).stream()
					.filter(a->a.getOperatorId().equals(bean.getApprovalUserId())).findFirst();
			Logger.verifyEquals(7, operationlogList.get().getInvoiceType(), "验证数据库Ymt_InvoiceOperationLog 中的字段InvoiceType=7提现单");
			Logger.verifyEquals(7, operationlogList.get().getOperationType(), "验证数据库Ymt_InvoiceOperationLog 中的字段OperationType=7拒绝支付（三级审批拒绝，单据作废）");	
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_RejectApproval_005() {
		Logger.start(true,"正例-审核拒绝--买家/买手提现单运营审核-invoiceId为空");
		try {
			//String invoiceId=applyBankForseller();
			//bean.setInvoiceId(invoiceId);
			bean.setApprovalLevel(1);
			bean.setApprovalResult("审核拒绝_"+TestDataManager.random());
			bean.setApprovalUserId(TestDataManager.getRandomIntNum(5));
			bean.setApprovalUserLoginId("LoginId_"+TestDataManager.getRandomIntNum(5));
			call.setData(bean);
			call.callService();		
			
			Logger.verifyEquals("false", call.getSuccess(), "验证Success");
			Logger.verifyEquals("400", call.getCode(), "验证Code");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_RejectApproval_006() {
		Logger.start(true,"正例-审核拒绝--买家/买手提现单运营审核-approvalLevel为空");
		try {
			String invoiceId=applyBankForseller();
			bean.setInvoiceId(invoiceId);
			//bean.setApprovalLevel(1);
			bean.setApprovalResult("一级审核_"+TestDataManager.random());
			bean.setApprovalUserId(TestDataManager.getRandomIntNum(5));
			bean.setApprovalUserLoginId("LoginId_"+TestDataManager.getRandomIntNum(5));
			call.setData(bean);
			call.callService();		
			
			Logger.verifyEquals("false", call.getSuccess(), "验证Success");
			Logger.verifyEquals("400", call.getCode(), "验证Code");	
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_RejectApproval_007() {
		Logger.start(true,"正例-审核拒绝--买手提现单运营审核-提现到银行卡-一级审核拒绝-安利会");
		try {
			//1:检查计数表Ymt_WithDrawCounter 一天一次是否已经计数
			//2:如果times=1 表示计数一次,不能再创建
			//3:修改计数times=0
			//4:删除当天的申请记录Ymt_WithDrawInvoice
			Logger.comment("### 处理安利会计数begin ###########");
			SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
			LocalDateTime l=LocalDateTime.now();
			String begin=l.getYear()+"-"+l.getMonthValue()+"-"+l.getDayOfMonth()+" 00:00:00";
			ymtcounter.createCriteria().andCounterNameEqualTo("withdrawtimes").andTargetIdEqualTo("User"+userId+"_Type5")
			.andCycleTimeEqualTo(sf.parse(begin));
			
			List<Ymt_WithDrawCounter> counters=WithdrawWapper.selectYmtWithDrawCounter(ymtcounter);
			if(counters.size()==1)
			{
				Ymt_WithDrawCounter counter=counters.get(0);
				counter.setTimes(0);
				Map<String, Object> parameter=new HashMap<String, Object>();
				parameter.put("record", counter);
				parameter.put("example", ymtcounter);
				int updateCount=WithdrawWapper.updateCounterByExampleSelective(parameter);
				Logger.comment("### updateCount #### "+updateCount);
				
				ymtinvoive.createCriteria().andApplyTimeGreaterThanOrEqualTo(sf.parse(begin));
				int deletCount = WithdrawWapper.deleteByExample(ymtinvoive);
				Logger.comment("## deletCount # "+deletCount);
			}
			Logger.comment("### 处理安利会计数begin ###########");
			Logger.comment("############ 安利会买家申请 begin ################");
			applyBankWithDrawForBuyerBean bean2=new applyBankWithDrawForBuyerBean();
			applyBankWithDrawForBuyerCall call2=new applyBankWithDrawForBuyerCall();
			//给帐号充值
			String accountid = AccountCallServiceV2.getAccountId(userId, 5);
			AccountCallServiceV2.resetAccount(accountid, new BigDecimal(999999),
					new BigDecimal(0));
			//冻结资金
			BigDecimal freeze= WithdrawWapper.getSumFreezebyUserId(userId);
			Logger.comment("################冻结资金："+freeze);
			//查看账户余额
			BigDecimal balance=AccountCallServiceV2.getAccountBalance(userId, 5);
			Logger.comment("################账户余额："+balance);
			
			bean2.setUserId(userId);
			bean2.setWithDrawChannel(1);
			bean2.setAccountTypeId(5);//提现帐户类型Id，默认值:1.人民币余额帐户 5安利会
		    bean2.setWithDrawAmount(new BigDecimal(10));
		    bean2.setBusinessNo(new TestDataManager().getRandomNum(8));
	        bean2.setRemark("测试提现到国际银行卡");
	        bean2.setApplyUserId(userId);
	        bean2.setApplyLoginId(userName);
	        
	        bean2.setBankAccountName(fundAccountName_buer);
	        bean2.setBankAccountNo(fundAccountNo_buer);
	        bean2.setFundAccountId(fundAccountId_buer);
		    bean2.setCurrencyType(1);//1 人名币
	        bean2.setIdempotentNo(new TestDataManager().getRandomNum(8));
	        
			call2.setData(bean2);
			call2.callService();		
			Logger.comment("############ 安利会买家申请 end ################");
			String invoiceId=call2.getInvoiceId();
			
			bean.setInvoiceId(invoiceId);
			bean.setApprovalLevel(1);
			bean.setApprovalResult("一级审核_"+TestDataManager.random());
			bean.setApprovalUserId(TestDataManager.getRandomIntNum(5));
			bean.setApprovalUserLoginId("LoginId_"+TestDataManager.getRandomIntNum(5));
			call.setData(bean);
			call.callService();	
			
			check( invoiceId,-1,1) ;
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_RejectApproval_008() {
		Logger.start(true,"正例-审核拒绝--买手提现单运营审核-提现到支付宝-一级审核拒绝-安利会");
		try {
			 //1:检查计数表Ymt_WithDrawCounter 一天一次是否已经计数
			//2:如果times=1 表示计数一次,不能再创建
			//3:修改计数times=0
			//4:删除当天的申请记录Ymt_WithDrawInvoice
			Logger.comment("### 处理安利会计数begin ###########");
			SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
			LocalDateTime l=LocalDateTime.now();
			String begin=l.getYear()+"-"+l.getMonthValue()+"-"+l.getDayOfMonth()+" 00:00:00";
			ymtcounter.createCriteria().andCounterNameEqualTo("withdrawtimes").andTargetIdEqualTo("User"+userId+"_Type5")
			.andCycleTimeEqualTo(sf.parse(begin));
			
			List<Ymt_WithDrawCounter> counters=WithdrawWapper.selectYmtWithDrawCounter(ymtcounter);
			if(counters.size()==1)
			{
				Ymt_WithDrawCounter counter=counters.get(0);
				counter.setTimes(0);
				Map<String, Object> parameter=new HashMap<String, Object>();
				parameter.put("record", counter);
				parameter.put("example", ymtcounter);
				int updateCount=WithdrawWapper.updateCounterByExampleSelective(parameter);
				Logger.comment("### updateCount #### "+updateCount);
				
				ymtinvoive.createCriteria().andApplyTimeGreaterThanOrEqualTo(sf.parse(begin));
				int deletCount = WithdrawWapper.deleteByExample(ymtinvoive);
				Logger.comment("## deletCount # "+deletCount);
			}
			Logger.comment("### 处理安利会计数end ###########");
			Logger.comment("############ 安利会买家申请 begin ################");
			applyAlipayWithDrawForBuyerBean bean2=new applyAlipayWithDrawForBuyerBean();
			applyAlipayWithDrawForBuyerCall call2=new applyAlipayWithDrawForBuyerCall();
			//给帐号充值
			String accountid = AccountCallServiceV2.getAccountId(userId, 5);
			AccountCallServiceV2.resetAccount(accountid, new BigDecimal(999999),
					new BigDecimal(0));
			
            bean2.setUserId(userId);
            bean2.setUserType(0);//用户类型(0买家，１买手）
            bean2.setAccountTypeId(5);//买手提现帐户类型:　1普通人民币账户 RmbAccount,15 拼邮溯源专项保证金,16 黑五专项保证金, 17 全球买手专项保证金,18 预售活动保证金,  19 直播保证金, 20 高客单价保证金中间帐户:　21 系统内部人民币账户
            bean2.setWithDrawAmount(new BigDecimal(15));
            bean2.setBusinessNo(new TestDataManager().getRandomNum(8));
            bean2.setRemark("测试提现到支付宝");
            bean2.setApplyUserId(userId);
            bean2.setApplyLoginId(userName);
            bean2.setAlipayAccountName(alipayAccountName_user);
            bean2.setAlipayAccountNo(alipayAccountNo_user);
            bean2.setFundAccountId(alipayAccountName_Id_user);
            bean2.setIdempotentNo(new TestDataManager().getRandomNum(8));
            bean2.setWithDrawChannel(2);//1.买家PC 2.买手PC站 3.运营后台-资金 4.买家App 5.买手App 6.保证金提现 7.码头提现到贝海 8.专项保证金 9.b2b 10.推手APP
            
			call2.setData(bean2);
			call2.callService();	
			Logger.comment("############ 安利会买家申请 end ################");
			String invoiceId=call2.getInvoiceId();
			
			bean.setInvoiceId(invoiceId);
			bean.setApprovalLevel(1);
			bean.setApprovalResult("一级审核_"+TestDataManager.random());
			bean.setApprovalUserId(TestDataManager.getRandomIntNum(5));
			bean.setApprovalUserLoginId("LoginId_"+TestDataManager.getRandomIntNum(5));
			call.setData(bean);
			call.callService();	
			
			check( invoiceId,-1,1) ;
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_RejectApproval_009() {
		Logger.start(true,"正例-审核拒绝--买手提现单运营审核-提现到支付宝-三级审核拒绝-安利会");
		try {
			 //1:检查计数表Ymt_WithDrawCounter 一天一次是否已经计数
			//2:如果times=1 表示计数一次,不能再创建
			//3:修改计数times=0
			//4:删除当天的申请记录Ymt_WithDrawInvoice
			Logger.comment("### 处理安利会计数begin ###########");
			SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
			LocalDateTime l=LocalDateTime.now();
			String begin=l.getYear()+"-"+l.getMonthValue()+"-"+l.getDayOfMonth()+" 00:00:00";
			ymtcounter.createCriteria().andCounterNameEqualTo("withdrawtimes").andTargetIdEqualTo("User"+userId+"_Type5")
			.andCycleTimeEqualTo(sf.parse(begin));
			
			List<Ymt_WithDrawCounter> counters=WithdrawWapper.selectYmtWithDrawCounter(ymtcounter);
			if(counters.size()==1)
			{
				Ymt_WithDrawCounter counter=counters.get(0);
				counter.setTimes(0);
				Map<String, Object> parameter=new HashMap<String, Object>();
				parameter.put("record", counter);
				parameter.put("example", ymtcounter);
				int updateCount=WithdrawWapper.updateCounterByExampleSelective(parameter);
				Logger.comment("### updateCount #### "+updateCount);
				
				ymtinvoive.createCriteria().andApplyTimeGreaterThanOrEqualTo(sf.parse(begin));
				int deletCount = WithdrawWapper.deleteByExample(ymtinvoive);
				Logger.comment("## deletCount # "+deletCount);
			}
			Logger.comment("### 处理安利会计数end ###########");
			Logger.comment("############ 安利会买家申请 begin ################");
			applyAlipayWithDrawForBuyerBean bean2=new applyAlipayWithDrawForBuyerBean();
			applyAlipayWithDrawForBuyerCall call2=new applyAlipayWithDrawForBuyerCall();
			//给帐号充值
			String accountid = AccountCallServiceV2.getAccountId(userId, 5);
			AccountCallServiceV2.resetAccount(accountid, new BigDecimal(999999),
					new BigDecimal(0));
			
            bean2.setUserId(userId);
            bean2.setUserType(0);//用户类型(0买家，１买手）
            bean2.setAccountTypeId(5);//买手提现帐户类型:　1普通人民币账户 RmbAccount,15 拼邮溯源专项保证金,16 黑五专项保证金, 17 全球买手专项保证金,18 预售活动保证金,  19 直播保证金, 20 高客单价保证金中间帐户:　21 系统内部人民币账户
            bean2.setWithDrawAmount(new BigDecimal(15));
            bean2.setBusinessNo(new TestDataManager().getRandomNum(8));
            bean2.setRemark("测试提现到支付宝");
            bean2.setApplyUserId(userId);
            bean2.setApplyLoginId(userName);
            bean2.setAlipayAccountName(alipayAccountName_user);
            bean2.setAlipayAccountNo(alipayAccountNo_user);
            bean2.setFundAccountId(alipayAccountName_Id_user);
            bean2.setIdempotentNo(new TestDataManager().getRandomNum(8));
            bean2.setWithDrawChannel(2);//1.买家PC 2.买手PC站 3.运营后台-资金 4.买家App 5.买手App 6.保证金提现 7.码头提现到贝海 8.专项保证金 9.b2b 10.推手APP
            
			call2.setData(bean2);
			call2.callService();	
			Logger.comment("############ 安利会买家申请 end ################");
			String invoiceId=call2.getInvoiceId();
			
			PassApprovalBean pbean=new  PassApprovalBean();
			PassApprovalCall pcall=new PassApprovalCall();
			//一级审核通过
			pbean.setInvoiceId(invoiceId);
			pbean.setApprovalLevel(1);
			pbean.setApprovalResult("一级审核通过_"+TestDataManager.random());
			pbean.setApprovalUserId(TestDataManager.getRandomIntNum(5));
			pbean.setApprovalUserLoginId("LoginId_"+TestDataManager.getRandomIntNum(5));
			pcall.setData(pbean);
			pcall.callService();
			//二级审核通过
			pbean.setApprovalLevel(2);
			pbean.setApprovalResult("二级审核通过_"+TestDataManager.random());
			pbean.setApprovalUserId(TestDataManager.getRandomIntNum(5));
			pbean.setApprovalUserLoginId("LoginId_"+TestDataManager.getRandomIntNum(5));
			pcall.setData(pbean);
			pcall.callService();
			//三级审核拒绝
			bean.setInvoiceId(invoiceId);
			bean.setApprovalLevel(3);
			bean.setApprovalResult("三级审核拒绝_"+TestDataManager.random());
			bean.setApprovalUserId(TestDataManager.getRandomIntNum(5));
			bean.setApprovalUserLoginId("LoginId_"+TestDataManager.getRandomIntNum(5));
			call.setData(bean);
			call.callService();	
			
			check_WithDrawInvoice( invoiceId,-1,5) ;	
			
			Logger.comment("2:验证数据表 InvoiceOperationLog 单据操作日志表");
			
			ymtoperationlog.createCriteria().andInvoiceIdEqualTo(invoiceId);
			Optional<Ymt_InvoiceOperationLog>  operationlogList=WithdrawWapper.selectYmtInvoiceOperationLog(ymtoperationlog).stream()
					.filter(a->a.getOperatorId().equals(bean.getApprovalUserId())).findFirst();
			Logger.verifyEquals(7, operationlogList.get().getInvoiceType(), "验证数据库Ymt_InvoiceOperationLog 中的字段InvoiceType=7提现单");
			Logger.verifyEquals(7, operationlogList.get().getOperationType(), "验证数据库Ymt_InvoiceOperationLog 中的字段OperationType=7拒绝支付（三级审批拒绝，单据作废）");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}